#ifndef _BASE64_H_
#define _BASE64_H_

#ifdef __cplusplus
extern "C" {
#endif

/* Calculate needed length for encoding */ 
int base64_needed_encoded_length(int length_of_data);

/* Calculate needed length for decoding */ 
int base64_needed_decoded_length(int length_of_encoded_data);

/**
  Encode a data as base64.

  Note: We assert that dst is pre-allocated to correct size.
        See base64_needed_encoded_length().
*/ 
int base64_encode(const void *src, size_t src_len, char *dst);
/**
  Decode a base64 string

  SYNOPSIS
    base64_decode()
    src      Pointer to base64-encoded string
    len      Length of string at 'src'
    dst      Pointer to location where decoded data will be stored
    end_ptr  Pointer to variable that will refer to the character
             after the end of the encoded data that were decoded. Can
             be NULL.

  DESCRIPTION

    The base64-encoded data in the range ['src','*end_ptr') will be
    decoded and stored starting at 'dst'.  The decoding will stop
    after 'len' characters have been read from 'src', or when padding
    occurs in the base64-encoded data. In either case: if 'end_ptr' is
    non-null, '*end_ptr' will be set to point to the character after
    the last read character, even in the presence of error.

  NOTE
    We assert that 'dst' is pre-allocated to correct size.

  SEE ALSO
    base64_needed_decoded_length().

  RETURN VALUE
    Number of bytes written at 'dst' or -1 in case of failure
*/ 
int base64_decode(const char *src_base, size_t len,
		  void *dst, const char **end_ptr);

#ifdef __cplusplus
}
#endif

#endif /* _BASE64_H_ */
